
/*
 * Copyright (C) WeGuide 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package humrum.weguide.util;

/**
 * Class that draw a custom marker on map
 */

import humrum.weguide.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class WeguideMarker extends Overlay {

	private GeoPoint geop;
	private Context _context;
	
	public WeguideMarker(GeoPoint geo, Context context) {
		super();
		_context = context;
		geop = geo;
	}
	
	/**
	 * Override draw method
	 */
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		final Projection projection = mapView.getProjection();
		final Point pt = new Point();
		projection.toPixels(geop, pt);
		
		/** draw bitmap */
		final Bitmap marker = BitmapFactory.decodeResource(_context.getResources(), R.drawable.icon);
		canvas.drawBitmap(marker, pt.x, (pt.y - marker.getHeight()), null);
		super.draw(canvas, mapView, shadow);
	}

}
